package com.example.demo.entity;

import cn.ljserver.tool.weboffice.v3.model.FileInfo;
import com.easy.query.core.annotation.Table;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.RequiredArgsConstructor;

import java.time.LocalDateTime;

@Table("t_file")
@Data
@Builder
@AllArgsConstructor
@RequiredArgsConstructor
public class File {

    private String id;

    @Builder.Default
    private int version = 1;

    private String name;

    private long size;

    private String url;

    private LocalDateTime createTime;

    private LocalDateTime modifyTime;

    private long creatorId;

    private long modifierId;

    public int copyForNewVersion() {
        return version + 1;
    }

    /**
     * 转换为适用与web office的FileInfo
     */
    public FileInfo toFileInfo() {
        return FileInfo.builder()
                .id(this.id)
                .version(this.version)
                .name(this.name)
                .size(this.size)
                .createTime(this.createTime)
                .modifyTime(this.modifyTime)
                .creatorId(String.valueOf(this.creatorId))
                .modifierId(String.valueOf(this.modifierId))
                .build();
    }
}